package com.mark.web.sys.controller.frontend;

import com.mark.common.ServerResponse;
import com.mark.common.exception.Campuso2oException;
import com.mark.web.sys.entity.vo.DictVo;
import com.mark.web.sys.service.IDictService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @Description: 字典管理的控制器
 * @Author: Mark
 * @CreateDate: 2019/6/8 19:20
 * @Version: 2.0
 * @Copyright : 豆浆油条个人非正式工作室
 */
@Api(tags = "系统-字典管理")
@RestController
@RequestMapping("/sys/dict/")
public class DictController {

    private final IDictService iDictService;

    @Autowired
    public DictController(IDictService iDictService) {
        this.iDictService = iDictService;
    }

    @ApiOperation(value = "根据父级字典id获取子字典列表")
    @ApiImplicitParam(name = "parentId",value = "父级字典id")
    @PostMapping("getDictByParentId")
    public ServerResponse<List<DictVo>> getDictByParentId(@RequestParam("parentId") Integer parentId){
        if(null == parentId){
            throw new Campuso2oException("请输入父级字典id");
        }
        List<DictVo> dictVoList = iDictService.getDictByParentId(parentId);
        return ServerResponse.model(dictVoList);
    }

}
